//
//  ZH_MineClassStateTableViewCell.m
//  WisdomStar
//
//  Created by zhangliwen on 2018/11/16.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_MineClassStateTableViewCell.h"
@interface ZH_MineClassStateTableViewCell()
@property (nonatomic,strong)UILabel *leftLabel;
//退款button
@property (nonatomic,weak)UIButton *refundAgreeButton;
//拒绝退款
@property (nonatomic,weak)UIButton *refundDisagreeButton;
//取消
@property (nonatomic,weak)UIButton *dissButton;
@end
@implementation ZH_MineClassStateTableViewCell
///创建
+ (instancetype)cellWithTableView:(UITableView*)tableView
{
    static NSString *ID = @"ZH_MineClassStateTableViewCell";
    ZH_MineClassStateTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if(cell == nil){
        cell = [[ZH_MineClassStateTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}
///初始化
-(void)initDefault
{
    [self unShowClickEffect];
    self.bottomShortLineImage.hidden = NO;
}
- (void)loadSubviewConstraints{
    [self.dissButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(FITSCALE(9));
        make.right.equalTo(self.contentView).offset(FITSCALE(-10));
        make.width.mas_equalTo(FITSCALE(60));
        make.height.mas_equalTo(FITSCALE(50));
        make.bottom.equalTo(self.contentView).offset(FITSCALE(-9));
    }];
    [self.refundAgreeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.dissButton);
        make.height.mas_equalTo(FITSCALE(29));
        make.width.mas_equalTo(FITSCALE(50));
        make.right.equalTo(self.dissButton.mas_left).offset(FITSCALE(-5));
    }];
    [self.refundDisagreeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.dissButton);
        make.width.mas_equalTo(FITSCALE(81));
        make.height.mas_equalTo(FITSCALE(29));
        make.right.equalTo(self.refundAgreeButton.mas_left).offset(FITSCALE(-5));
    }];
   
    [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset(FITSCALE(10));
    }];
}
- (void)updataUI:(NSDictionary *)data{
    if (data) {
        self.leftLabel.text =[NSString stringWithFormat:@"合计:%@",data[@"price"]];
        NSString *string = [NSString stringWithFormat:@"%@",data[@"status"]];
        if ([string isEqualToString:@"1"]) {
            
        }
        else{
            self.refundAgreeButton.hidden = YES;
            [self.refundDisagreeButton mas_updateConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(self.dissButton.mas_left).offset(FITSCALE(-5));
            }];
            [self.refundDisagreeButton setTitle:@"申请退款" forState:UIControlStateNormal];
        }
    }
}
#pragma mark - getter,setter
- (UILabel *)leftLabel{
    if (!_leftLabel) {
        UILabel *label = [UILabel createLabelWithText:@"合计:" font:kFontSize_28];
        label.textColor = kFontColorRed;
        NSMutableAttributedString *attr = [[NSMutableAttributedString alloc]initWithString:label.text];
        NSDictionary *dic = @{NSFontAttributeName:kFontSize_26,NSForegroundColorAttributeName:kFontColorBlack};
        [attr setAttributes:dic range:[label.text rangeOfString: @"合计:"]];
        label.attributedText = attr;
        [self.contentView addSubview:_leftLabel = label];
    }
    return _leftLabel;
}
- (UIButton *)refundAgreeButton{
    if (!_refundAgreeButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"付款" target:self action:nil];
        [button setTitleColor:[UIColor colorWithHexString:@"#00C9AE"] forState:UIControlStateNormal];
        button.layer.cornerRadius = FITSCALE(14);
        button.layer.borderWidth = FITSCALE(1);
        button.layer.borderColor = [UIColor colorWithHexString:@"#00C9AE"].CGColor;
        button.layer.masksToBounds = YES;
        button.clipsToBounds = YES;
        button.tag = 1;
        button.titleLabel.font = kFontSize_28;
        [self.contentView addSubview:_refundAgreeButton = button];
    }
    return _refundAgreeButton;
}
- (UIButton *)refundDisagreeButton{
    if (!_refundDisagreeButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"取消订单" target:self action:nil];
        [button setTitleColor:[UIColor colorWithHexString:@"#555555"] forState:UIControlStateNormal];
        button.layer.cornerRadius = FITSCALE(14);
        button.layer.borderWidth = FITSCALE(1);
        button.layer.borderColor = [UIColor colorWithHexString:@"#555555"].CGColor;
        button.layer.masksToBounds = YES;
        button.titleLabel.font = kFontSize_28;
        button.clipsToBounds = YES;
        [self.contentView addSubview:_refundDisagreeButton = button];
    }
    return _refundDisagreeButton;
}
- (UIButton *)dissButton{
    if (!_dissButton) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@" 查看 " target:self action:nil];
        [button setTitleColor:kFontColorWhite forState:UIControlStateNormal];
        button.layer.cornerRadius = FITSCALE(14);
        button.backgroundColor = [UIColor colorWithHexString:@"#00C9AE"];
        button.layer.masksToBounds = YES;
        button.titleLabel.font = kFontSize_28;
        button.clipsToBounds = YES;
        [self.contentView addSubview:_dissButton = button];
    }
    return _dissButton;
}

@end
